<html>
<head><meta charset="utf-8"><title>Stabilizing `--pretty=expanded` · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Stabilizing.20.60--pretty.3Dexpanded.60.html">Stabilizing `--pretty=expanded`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="211830447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Stabilizing%20%60--pretty%3Dexpanded%60/near/211830447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Stabilizing.20.60--pretty.3Dexpanded.60.html#211830447">(Sep 30 2020 at 21:36)</a>:</h4>
<p>I'd like to resolve <a href="https://github.com/rust-lang/rust/issues/43364">#43364</a> somehow to get <code>cbindgen</code> working on stable.</p>
<p>What do you think about guaranteed that the pretty-printed code should provide?<br>
I think we can guarantee that the code parses (but not necessarily resolves), and stabilize as is.</p>



<a name="211838946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Stabilizing%20%60--pretty%3Dexpanded%60/near/211838946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Stabilizing.20.60--pretty.3Dexpanded.60.html#211838946">(Sep 30 2020 at 21:56)</a>:</h4>
<p>modulo unstable implementation details (e.g., it might not parse on stable due to feature use by std macros that get expanded away)</p>



<a name="211838978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Stabilizing%20%60--pretty%3Dexpanded%60/near/211838978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Stabilizing.20.60--pretty.3Dexpanded.60.html#211838978">(Sep 30 2020 at 21:57)</a>:</h4>
<p>well "parse" might be the wrong word there, I guess, but not sure what you mean by parse :)</p>



<a name="211840702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Stabilizing%20%60--pretty%3Dexpanded%60/near/211840702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Stabilizing.20.60--pretty.3Dexpanded.60.html#211840702">(Sep 30 2020 at 22:16)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> looking at bindgen internal docs, <a href="https://github.com/eqrion/cbindgen/blob/master/internals.md">https://github.com/eqrion/cbindgen/blob/master/internals.md</a>, it doesn't look like that's anything beyond proc macro at crate level abilities - and maybe less than that. I'm thinking maybe it's worth trying to push this through as a proc macro with the eager expansion rfcs? That would also feel more "first class" I imagine. I'm not opposed to stabilizing expanded, though, I guess.</p>



<a name="212910007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Stabilizing%20%60--pretty%3Dexpanded%60/near/212910007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Stabilizing.20.60--pretty.3Dexpanded.60.html#212910007">(Oct 10 2020 at 10:41)</a>:</h4>
<blockquote>
<p>modulo unstable implementation details (e.g., it might not parse on stable due to feature use by std macros that get expanded away)</p>
</blockquote>
<p>Yes, that's an issue.<br>
cbindgen will see the potentially unstable syntax no matter what is the source of its input - pretty printing or eager expansion.<br>
However, that syntax is going to be parsed by ~<code>syn</code> rather than  by rustc parser, which isn't mandated to report stability errors.</p>



<a name="212910079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Stabilizing%20%60--pretty%3Dexpanded%60/near/212910079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Stabilizing.20.60--pretty.3Dexpanded.60.html#212910079">(Oct 10 2020 at 10:43)</a>:</h4>
<p>I'm not actually sure what is it's policy regarding this, but I suspect that changes in expanded code will be addressed in the same way as new language features that may appear in code with time - by bumping the <code>syn</code>'s version.</p>



<a name="212910183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Stabilizing%20%60--pretty%3Dexpanded%60/near/212910183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Stabilizing.20.60--pretty.3Dexpanded.60.html#212910183">(Oct 10 2020 at 10:45)</a>:</h4>
<blockquote>
<p>I'm thinking maybe it's worth trying to push this through as a proc macro with the eager expansion rfcs?</p>
</blockquote>
<p>The difference is that eager expansion will take ~years to get to stable, and pretty-printing can be stabilized right away.<br>
That pretty much mirrors the situation with custom derives which were initially stabilized as working solely through pretty-printing, and then migrated to tokens in a couple of years.</p>



<a name="212910473"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Stabilizing%20%60--pretty%3Dexpanded%60/near/212910473" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Stabilizing.20.60--pretty.3Dexpanded.60.html#212910473">(Oct 10 2020 at 10:52)</a>:</h4>
<p>One more alternative: <code>--emit expanded</code> can actually produce serialized tokens instead of text, in the same format as used in <code>.rmeta</code>.<br>
Then a new function in the <code>proc_macro</code> crate can read them back into a token stream, like <code>let tokens = proc_macro::deserialize_tokens("my_crate.rmeta")</code>.</p>



<a name="212910910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Stabilizing%20%60--pretty%3Dexpanded%60/near/212910910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Stabilizing.20.60--pretty.3Dexpanded.60.html#212910910">(Oct 10 2020 at 11:04)</a>:</h4>
<p>You actually may need a full crate metadata to decode tokens, due to all the hygiene structures etc.<br>
So <code>--emit expanded</code> could actually perform regular compilation, produce a regular <code>my_crate.rmeta</code> or <code>my_crate.rlib</code>, and just encode one more token stream into the metadata.<br>
Then you can load it as a regular crate with <code>extern crate my_crate;</code> or through <code>Cargo.toml</code>, but the loaded crate will contain one additional function - <code>my_crate::deserialize_tokens()</code> (or equivalent), through which its tokens can be obtained.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>